#include "ChallengePreviewDialog.h"
#include "../../../model/proxy/ChanllengeProxy.h"
#include "../../../model/proxy/UserProxy.h"
#include "../../../net/NetController.h"

ChallengePreviewDialog::ChallengePreviewDialog(void)
	:mName1(NULL),mName2(NULL),mGetGold(NULL),mGetExp(NULL),mLostGold(NULL)
{
}

ChallengePreviewDialog::~ChallengePreviewDialog(void)
{
	CC_SAFE_RELEASE(mName1);
	CC_SAFE_RELEASE(mName2);
	CC_SAFE_RELEASE(mGetGold);
	CC_SAFE_RELEASE(mGetExp);
	CC_SAFE_RELEASE(mLostGold);
}

bool ChallengePreviewDialog::init()
{
	return true;
}

SEL_MenuHandler ChallengePreviewDialog::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onDoItClick", ChallengePreviewDialog::onDoItClick);
	return NULL;
}

SEL_CCControlHandler ChallengePreviewDialog::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onChallengeBtnClick", ChallengePreviewDialog::onChallengeBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onReturnBtnClick", ChallengePreviewDialog::onReturnBtnClick);
	return NULL;
}

bool ChallengePreviewDialog::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName1", CCLabelTTF *, this->mName1);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName2", CCLabelTTF *, this->mName2);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mGetGold", CCLabelTTF *, this->mGetGold);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mGetExp", CCLabelTTF *, this->mGetExp);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mLostGold", CCLabelTTF *, this->mLostGold);
	return false;
}

void ChallengePreviewDialog::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{

}

void ChallengePreviewDialog::onEnter()
{
	ModelDialog::onEnter();
}

void ChallengePreviewDialog::onExit()
{
	ModelDialog::onExit();
}

void ChallengePreviewDialog::refresh()
{
	ChallengeEnemyInfo* challengeEnemyInfo = ChanllengeProxy::getSingletonPtr()->curChallengeEnemyInfo;
	mName1->setString(UserProxy::getSingletonPtr()->userVO.name.c_str());
	mName2->setString(challengeEnemyInfo->name.c_str());
	mGetGold->setString(fcs("+%d", challengeEnemyInfo->succeedGold));
	mGetExp->setString(fcs("+%d", challengeEnemyInfo->succeedExp));
	mLostGold->setString(fcs("-%d", challengeEnemyInfo->failedGold));
}

void ChallengePreviewDialog::_onNotification( CCObject* object )
{
	
}

void ChallengePreviewDialog::onDoItClick(CCObject* pSender)
{
    
}

void ChallengePreviewDialog::onChallengeBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	if(UserProxy::getSingletonPtr()->userVO.powerCur <= 0)
		Framework::getSingletonPtr()->popup("StaminaLackDialog");
    else
    {
        ChallengeEnemyInfo* challengeEnemyInfo = ChanllengeProxy::getSingletonPtr()->curChallengeEnemyInfo;
        NetController::getSingletonPtr()->challengePlayer(challengeEnemyInfo->gid);
    }
    close();
}

void ChallengePreviewDialog::onReturnBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	close();
}
